<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActionView::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActionView::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_view/base_rb.html">
                vendor/rails/actionpack/lib/action_view/base.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_view/helpers/active_record_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/actionpack/lib/action_view/helpers/form_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Action View templates can be written in three ways. If the <a
href="Base.html#M002164">template</a> file has a <tt>.erb</tt> (or
<tt>.rhtml</tt>) extension then it uses a mixture of ERb (included in Ruby)
and HTML. If the <a href="Base.html#M002164">template</a> file has a
<tt>.builder</tt> (or <tt>.rxml</tt>) extension then Jim Weirich&#8216;s <a
href="../Builder/XmlMarkup.html">Builder::XmlMarkup</a> library is used. If
the <a href="Base.html#M002164">template</a> file has a <tt>.rjs</tt>
extension then it will use
ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.
</p>
<h1>ERb</h1>
<p>
You trigger ERb by using embeddings such as &lt;% %&gt;, &lt;% -%&gt;, and
&lt;%= %&gt;. The &lt;%= %&gt; tag set is used when you want output.
Consider the following loop for names:
</p>
<pre>
  &lt;b&gt;Names of all the people&lt;/b&gt;
  &lt;% for person in @people %&gt;
    Name: &lt;%= person.name %&gt;&lt;br/&gt;
  &lt;% end %&gt;
</pre>
<p>
The loop is setup in regular embedding tags &lt;% %&gt; and the name is
written using the output embedding tag &lt;%= %&gt;. Note that this is not
just a usage suggestion. Regular output functions like print or puts
won&#8216;t work with ERb templates. So this would be wrong:
</p>
<pre>
  Hi, Mr. &lt;% puts &quot;Frodo&quot; %&gt;
</pre>
<p>
If you absolutely must write from within a function, you can use the
TextHelper#concat.
</p>
<p>
&lt;%- and -%&gt; suppress leading and trailing whitespace, including the
trailing newline, and can be used interchangeably with &lt;% and %&gt;.
</p>
<h2>Using sub templates</h2>
<p>
Using sub templates allows you to sidestep tedious replication and extract
common display structures in shared templates. The classic example is the
use of a header and footer (even though the Action Pack-way would be to use
Layouts):
</p>
<pre>
  &lt;%= render &quot;shared/header&quot; %&gt;
  Something really specific and terrific
  &lt;%= render &quot;shared/footer&quot; %&gt;
</pre>
<p>
As you see, we use the output embeddings for the render methods. The render
call itself will just return a string holding the result of the rendering.
The output embedding writes it to the current <a
href="Base.html#M002164">template</a>.
</p>
<p>
But you don&#8216;t have to restrict yourself to static includes. Templates
can share variables amongst themselves by using instance variables defined
using the regular embedding tags. Like this:
</p>
<pre>
  &lt;% @page_title = &quot;A Wonderful Hello&quot; %&gt;
  &lt;%= render &quot;shared/header&quot; %&gt;
</pre>
<p>
Now the header can pick up on the <tt>@page_title</tt> variable and use it
for outputting a title tag:
</p>
<pre>
  &lt;title&gt;&lt;%= @page_title %&gt;&lt;/title&gt;
</pre>
<h2>Passing local variables to sub templates</h2>
<p>
You can pass local variables to sub templates by using a hash with the
variable names as keys and the objects as values:
</p>
<pre>
  &lt;%= render &quot;shared/header&quot;, { :headline =&gt; &quot;Welcome&quot;, :person =&gt; person } %&gt;
</pre>
<p>
These can now be accessed in <tt>shared/header</tt> with:
</p>
<pre>
  Headline: &lt;%= headline %&gt;
  First name: &lt;%= person.first_name %&gt;
</pre>
<p>
If you need to find out whether a certain local variable has been assigned
a value in a particular render call, you need to use the following pattern:
</p>
<pre>
  &lt;% if local_assigns.has_key? :headline %&gt;
    Headline: &lt;%= headline %&gt;
  &lt;% end %&gt;
</pre>
<p>
Testing using <tt>defined? headline</tt> will not work. This is an
implementation restriction.
</p>
<h2><a href="Template.html">Template</a> caching</h2>
<p>
By default, <a href="../Rails.html">Rails</a> will compile each <a
href="Base.html#M002164">template</a> to a method in order to render it.
When you alter a <a href="Base.html#M002164">template</a>, <a
href="../Rails.html">Rails</a> will check the file&#8216;s modification
time and recompile it.
</p>
<h2><a href="../Builder.html">Builder</a></h2>
<p>
<a href="../Builder.html">Builder</a> templates are a more programmatic
alternative to ERb. They are especially useful for generating XML content.
An XmlMarkup object named <tt>xml</tt> is automatically made available to
templates with a <tt>.builder</tt> extension.
</p>
<p>
Here are some basic examples:
</p>
<pre>
  xml.em(&quot;emphasized&quot;)                              # =&gt; &lt;em&gt;emphasized&lt;/em&gt;
  xml.em { xml.b(&quot;emph &amp; bold&quot;) }                   # =&gt; &lt;em&gt;&lt;b&gt;emph &amp;amp; bold&lt;/b&gt;&lt;/em&gt;
  xml.a(&quot;A Link&quot;, &quot;href&quot;=&gt;&quot;http://onestepback.org&quot;) # =&gt; &lt;a href=&quot;http://onestepback.org&quot;&gt;A Link&lt;/a&gt;
  xml.target(&quot;name&quot;=&gt;&quot;compile&quot;, &quot;option&quot;=&gt;&quot;fast&quot;)   # =&gt; &lt;target option=&quot;fast&quot; name=&quot;compile&quot;\&gt;
                                                    # NOTE: order of attributes is not specified.
</pre>
<p>
Any method with a block will be treated as an XML markup tag with nested
markup in the block. For example, the following:
</p>
<pre>
  xml.div {
    xml.h1(@person.name)
    xml.p(@person.bio)
  }
</pre>
<p>
would produce something like:
</p>
<pre>
  &lt;div&gt;
    &lt;h1&gt;David Heinemeier Hansson&lt;/h1&gt;
    &lt;p&gt;A product of Danish Design during the Winter of '79...&lt;/p&gt;
  &lt;/div&gt;
</pre>
<p>
A full-length RSS example actually used on Basecamp:
</p>
<pre>
  xml.rss(&quot;version&quot; =&gt; &quot;2.0&quot;, &quot;xmlns:dc&quot; =&gt; &quot;http://purl.org/dc/elements/1.1/&quot;) do
    xml.channel do
      xml.title(@feed_title)
      xml.link(@url)
      xml.description &quot;Basecamp: Recent items&quot;
      xml.language &quot;en-us&quot;
      xml.ttl &quot;40&quot;

      for item in @recent_items
        xml.item do
          xml.title(item_title(item))
          xml.description(item_description(item)) if item_description(item)
          xml.pubDate(item_pubDate(item))
          xml.guid(@person.firm.account.url + @recent_items.url(item))
          xml.link(@person.firm.account.url + @recent_items.url(item))

          xml.tag!(&quot;dc:creator&quot;, item.author_name) if item_has_creator?(item)
        end
      end
    end
  end
</pre>
<p>
More builder documentation can be found at <a
href="http://builder.rubyforge.org">builder.rubyforge.org</a>.
</p>
<h2>JavaScriptGenerator</h2>
<p>
JavaScriptGenerator templates end in <tt>.rjs</tt>. Unlike conventional
templates which are used to render the results of an action, these
templates generate instructions on how to modify an already rendered page.
This makes it easy to modify multiple elements on your page in one
declarative Ajax response. Actions with these templates are called in the
background with Ajax and make updates to the page where the request
originated from.
</p>
<p>
An instance of the JavaScriptGenerator object named <tt>page</tt> is
automatically made available to your <a
href="Base.html#M002164">template</a>, which is implicitly wrapped in an
ActionView::Helpers::PrototypeHelper#update_page block.
</p>
<p>
When an <tt>.rjs</tt> action is called with <tt>link_to_remote</tt>, the
generated JavaScript is automatically evaluated. Example:
</p>
<pre>
  link_to_remote :url =&gt; {:action =&gt; 'delete'}
</pre>
<p>
The subsequently rendered <tt>delete.rjs</tt> might look like:
</p>
<pre>
  page.replace_html  'sidebar', :partial =&gt; 'sidebar'
  page.remove        &quot;person-#{@person.id}&quot;
  page.visual_effect :highlight, 'user-list'
</pre>
<p>
This refreshes the sidebar, removes a person element and highlights the
user list.
</p>
<p>
See the ActionView::Helpers::PrototypeHelper::GeneratorMethods
documentation for more details.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M002160">exempt_from_layout</a>&nbsp;&nbsp;
      <a href="#M002161">process_view_paths</a>&nbsp;&nbsp;
      <a href="#M002164">template</a>&nbsp;&nbsp;
      <a href="#M002163">template_format</a>&nbsp;&nbsp;
      <a href="#M002162">view_paths=</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="../ERB/Util.html">ERB::Util</a></span>
        <span class="include-name">CompiledTemplates</span>
      </div>
    </div>

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="Base/ProxyModule.html" class="link">ActionView::Base::ProxyModule</a><br />

    </div>




    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">assigns</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">base_path</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">controller</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">helpers</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">output_buffer</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">template_extension</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">template_format</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">view_paths</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M002160" class="method-detail">
        <a name="M002160"></a>

        <div class="method-heading">
          <a href="#M002160" class="method-signature">
          <span class="method-name">exempt_from_layout</span><span class="method-args">(*extensions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Don&#8216;t render layouts for templates with the given extensions.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002160-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002160-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/base.rb, line 179</span>
179:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">exempt_from_layout</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">extensions</span>)
180:       <span class="ruby-identifier">regexps</span> = <span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">extension</span><span class="ruby-operator">|</span>
181:         <span class="ruby-identifier">extension</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">extension</span> <span class="ruby-operator">:</span> <span class="ruby-node">/\.#{Regexp.escape(extension.to_s)}$/</span>
182:       <span class="ruby-keyword kw">end</span>
183:       <span class="ruby-ivar">@@exempt_from_layout</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">regexps</span>)
184:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002161" class="method-detail">
        <a name="M002161"></a>

        <div class="method-heading">
          <a href="#M002161" class="method-signature">
          <span class="method-name">process_view_paths</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002161-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002161-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/base.rb, line 205</span>
205:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">process_view_paths</span>(<span class="ruby-identifier">value</span>)
206:       <span class="ruby-constant">ActionView</span><span class="ruby-operator">::</span><span class="ruby-constant">PathSet</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Array</span>(<span class="ruby-identifier">value</span>))
207:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M002164" class="method-detail">
        <a name="M002164"></a>

        <div class="method-heading">
          <a href="#M002164" class="method-signature">
          <span class="method-name">template</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Access the current <a href="Base.html#M002164">template</a> being rendered.
Returns a <a href="Template.html">ActionView::Template</a> object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002164-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002164-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/base.rb, line 282</span>
282:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">template</span>
283:       <span class="ruby-ivar">@_render_stack</span>.<span class="ruby-identifier">last</span>
284:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002163" class="method-detail">
        <a name="M002163"></a>

        <div class="method-heading">
          <a href="#M002163" class="method-signature">
          <span class="method-name">template_format</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The format to be used when choosing between multiple templates with the
same name but differing formats. See +Request#template_format+ for more
details.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002163-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002163-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/base.rb, line 270</span>
270:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">template_format</span>
271:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@template_format</span>
272:         <span class="ruby-ivar">@template_format</span>
273:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">controller</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:request</span>)
274:         <span class="ruby-ivar">@template_format</span> = <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">template_format</span>
275:       <span class="ruby-keyword kw">else</span>
276:         <span class="ruby-ivar">@template_format</span> = <span class="ruby-identifier">:html</span>
277:       <span class="ruby-keyword kw">end</span>
278:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002162" class="method-detail">
        <a name="M002162"></a>

        <div class="method-heading">
          <a href="#M002162" class="method-signature">
          <span class="method-name">view_paths=</span><span class="method-args">(paths)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002162-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002162-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/base.rb, line 233</span>
233:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">view_paths=</span>(<span class="ruby-identifier">paths</span>)
234:       <span class="ruby-ivar">@view_paths</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">process_view_paths</span>(<span class="ruby-identifier">paths</span>)
235:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>